 ﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data;

namespace WindowsForms.Class
{
    public class ConvertToList
    {
        private BookingDetails GetBookingDetailsDataTableRow(DataRow dr)
        {
            BookingDetails obj = new BookingDetails();
            obj.BookingDetailID = int.Parse(dr["BookingDetailID"].ToString());
            obj.BookingID = int.Parse(dr["BookingID"].ToString());
            obj.MenuID = int.Parse(dr["MenuID"].ToString());
            obj.MenuName = dr["MenuName"].ToString();
            obj.UnitName = dr["UnitName"].ToString();
            obj.Status = dr["Status"].ToString();
            obj.Price = int.Parse(dr["Price"].ToString());
            obj.Quantity = int.Parse(dr["Quantity"].ToString());
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());
            return obj;
        }

        private Bookings GetBookingsDataTableRow(DataRow dr)
        {
            Bookings obj = new Bookings();
            int a = int.Parse(dr["BookingID"].ToString());
            obj.BookingID = int.Parse(dr["BookingID"].ToString());
            obj.TableID = int.Parse(dr["TableID"].ToString());
            obj.StaffID = int.Parse(dr["StaffID"].ToString());
            obj.BookingNumber = dr["BookingNumber"].ToString();
            obj.BookingDate = Convert.ToDateTime(dr["BookingDate"].ToString());
            obj.TotalAmount = int.Parse(dr["TotalAmount"].ToString());
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());

            try
            {
                obj.TableName = dr["TableName"].ToString();
                obj.StaffName = dr["StaffName"].ToString();
            }
            catch { }
            
            return obj;
        }

        private HistoryBookings GetHistoryBookingsDataTableRow(DataRow dr)
        {
            HistoryBookings obj = new HistoryBookings();
            obj.HistoryBookingID = int.Parse(dr["HistoryBookingID"].ToString());
            obj.BookingID = int.Parse(dr["BookingID"].ToString());
            obj.MenuID = int.Parse(dr["MenuID"].ToString());
            obj.BookingDate = dr["BookingDate"].ToString();
            obj.Reason = dr["Reason"].ToString();
            obj.BookingNumber = dr["BookingNumber"].ToString();
            obj.TableName = dr["TableName"].ToString();
            obj.StaffName = dr["StaffName"].ToString();
            obj.MenuName = dr["MenuName"].ToString();
            obj.IsDeleted =  Convert.ToBoolean(dr["IsDeleted"].ToString());
            return obj;
        }

        private HistoryMenus GetHistoryMenusDataTableRow(DataRow dr)
        {
            HistoryMenus obj = new HistoryMenus();
            obj.HistoryMenuID = int.Parse(dr["HistoryMenuID"].ToString());
            obj.MenuID = int.Parse(dr["MenuID"].ToString());
            obj.Price = int.Parse(dr["Price"].ToString());
            obj.CreateDate =Convert.ToDateTime(dr["CreateDate"].ToString());
            obj.MenuName = dr["MenuName"].ToString();
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());
            return obj;
        }

        private MenuTypes GetMenuTypesDataTableRow(DataRow dr)
        {
            MenuTypes obj = new MenuTypes();
            obj.MenuTypeID =  int.Parse(dr["MenuTypeID"].ToString());
            obj.MenuTypeName = dr["MenuTypeName"].ToString();
            obj.Description = dr["Description"].ToString();
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());
            return obj;
        }

        private Menus GetMenusDataTableRow(DataRow dr)
        {
            Menus obj = new Menus();
            obj.MenuID = int.Parse(dr["MenuID"].ToString());
            obj.MenuTypeID = int.Parse(dr["MenuTypeID"].ToString());
            obj.MenuName = dr["MenuName"].ToString();
            obj.Price = int.Parse(dr["Price"].ToString());
            obj.UnitID = int.Parse(dr["UnitID"].ToString());
            obj.MenuTypeName = dr["MenuTypeName"].ToString();
            obj.UnitName = dr["UnitName"].ToString();
            obj.Picture = dr["Picture"].ToString();
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());
 			obj.Total = int.Parse(dr["Total"].ToString());            return obj;
        }

        private Regions GetRegionsDataTableRow(DataRow dr)
        {
            Regions obj = new Regions();
            obj.RegionID = int.Parse(dr["RegionID"].ToString());
            obj.RegionName = dr["RegionName"].ToString();
            obj.Description = dr["Description"].ToString();
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());
            return obj;
        }

        private Roles GetRolesDataTableRow(DataRow dr)
        {
            Roles obj = new Roles();
            obj.RoleID =int.Parse( dr["RoleID"].ToString());
            obj.RoleName = dr["RoleName"].ToString();
            obj.IsDelete = Convert.ToBoolean(dr["IsDelete"].ToString());
            return obj;
        }

        private Staffs GetStaffsDataTableRow(DataRow dr)
        {
            Staffs obj = new Staffs();
            obj.StaffID = int.Parse(dr["StaffID"].ToString());
            obj.RoleID = int.Parse(dr["RoleID"].ToString());
            obj.RoleName = dr["RoleName"].ToString();
            obj.UserName = dr["UserName"].ToString();
            obj.Password = dr["Password"].ToString();
            obj.StaffName = dr["StaffName"].ToString();
            obj.Address = dr["Address"].ToString();
            obj.BirthDate = Convert.ToDateTime(dr["BirthDate"].ToString());
            obj.Gender = Convert.ToBoolean(dr["Gender"].ToString());
            obj.PhoneNumber = dr["PhoneNumber"].ToString();
            obj.StartWorkDate = Convert.ToDateTime(dr["StartWorkDate"].ToString());
            obj.EndWorkDate = Convert.ToDateTime(dr["EndWorkDate"].ToString());
            obj.CreateDate = Convert.ToDateTime(dr["CreateDate"].ToString());
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());
            obj.IMEI = dr["IMEI"].ToString();

            return obj;
        }

        private Tables GetTablesDataTableRow(DataRow dr)
        {
            Tables obj = new Tables();
            obj.TableID = int.Parse(dr["TableID"].ToString());
            obj.TableName = dr["TableName"].ToString();
            obj.RegionID = int.Parse(dr["RegionID"].ToString());
            obj.RegionName = (dr["RegionName"].ToString());
            obj.Description = dr["Description"].ToString();
            obj.IsBlank = Convert.ToBoolean(dr["IsBlank"].ToString());
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());
            return obj;
        }

        private Units GetUnitsDataTableRow(DataRow dr)
        {
            Units obj = new Units();
            obj.UnitID = int.Parse(dr["UnitID"].ToString());
            obj.UnitName = dr["UnitName"].ToString();
            obj.Description = dr["Description"].ToString();
            obj.IsDeleted = Convert.ToBoolean(dr["IsDeleted"].ToString());
            return obj;
        }

        /////////////////////////////////////////////////////
        /// <summary>
        /// ConvertTolistBookingDetails
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<BookingDetails> ConvertTolistBookingDetails(DataTable dt)
        {
            List<BookingDetails> LstObj = new List<BookingDetails>();
            LstObj = new List<BookingDetails>(
                           (from dRow in dt.AsEnumerable()
                            select (GetBookingDetailsDataTableRow(dRow)))
                           );
            return LstObj;
        }

        /// <summary>
        /// ConvertTolistBooking
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Bookings> ConvertTolistBooking(DataTable dt)
        {
            List<Bookings> LstObj = new List<Bookings>();
            LstObj = new List<Bookings>(
                           (from dRow in dt.AsEnumerable()
                            select (GetBookingsDataTableRow(dRow)))
                           );
            return LstObj;
        }

        /// <summary>
        /// ConvertTolistHistoryBookings
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<HistoryBookings> ConvertTolistHistoryBookings(DataTable dt)
        {
            List<HistoryBookings> LstObj = new List<HistoryBookings>();
            LstObj = new List<HistoryBookings>(
                           (from dRow in dt.AsEnumerable()
                            select (GetHistoryBookingsDataTableRow(dRow)))
                           );
            return LstObj;
        }

        /// <summary>
        /// ConvertTolistHistoryMenus
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<HistoryMenus> ConvertTolistHistoryMenus(DataTable dt)
        {
            List<HistoryMenus> LstObj = new List<HistoryMenus>();
            LstObj = new List<HistoryMenus>(
                           (from dRow in dt.AsEnumerable()
                            select (GetHistoryMenusDataTableRow(dRow)))
                           );
            return LstObj;
        }

        /// <summary>
        /// ConvertTolistMenus
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Menus> ConvertTolistMenus(DataTable dt)
        {
            List<Menus> LstObj = new List<Menus>();
            LstObj = new List<Menus>(
                           (from dRow in dt.AsEnumerable()
                            select (GetMenusDataTableRow(dRow)))
                           );
            return LstObj;
        }

        /// <summary>
        /// ConvertTolistMenuTypes
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<MenuTypes> ConvertTolistMenuTypes(DataTable dt)
        {
            List<MenuTypes> LstObj = new List<MenuTypes>();
            LstObj = new List<MenuTypes>(
                           (from dRow in dt.AsEnumerable()
                            select (GetMenuTypesDataTableRow(dRow)))
                           );
            return LstObj;
        }

        /// <summary>
        /// ConvertTolistRegions
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Regions> ConvertTolistRegions(DataTable dt)
        {
            List<Regions> LstRegions = new List<Regions>();
            LstRegions = new List<Regions>(
                           (from dRow in dt.AsEnumerable()
                            select (GetRegionsDataTableRow(dRow)))
                           );
            return LstRegions;
        }

        /// <summary>
        /// ConvertTolistUnits
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Units> ConvertTolistUnits(DataTable dt)
        {
            List<Units> LstUnits = new List<Units>();
            LstUnits = new List<Units>(
                           (from dRow in dt.AsEnumerable()
                            select (GetUnitsDataTableRow(dRow)))
                           );
            return LstUnits;
        }

        /// <summary>
        /// ConvertTolistStaffs
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Staffs> ConvertTolistStaffs(DataTable dt)
        {
            List<Staffs> LstStaffs = new List<Staffs>();
            LstStaffs = new List<Staffs>(
                           (from dRow in dt.AsEnumerable()
                            select (GetStaffsDataTableRow(dRow)))
                           );
            return LstStaffs;
        }

        /// <summary>
        /// ConvertTolistRoles
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Roles> ConvertTolistRoles(DataTable dt)
        {
            List<Roles> LstRoles = new List<Roles>();
            LstRoles = new List<Roles>(
                           (from dRow in dt.AsEnumerable()
                            select (GetRolesDataTableRow(dRow)))
                           );
            return LstRoles;
        }

        /// <summary>
        /// ConvertTolistTables
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Tables> ConvertTolistTables(DataTable dt)
        {
            List<Tables> LstTables = new List<Tables>();
            LstTables = new List<Tables>(
                           (from dRow in dt.AsEnumerable()
                            select (GetTablesDataTableRow(dRow)))
                           );
            return LstTables;
        }
    }
}